import 'package:flutter/material.dart';
import 'package:village_android/common/mutil_tabs.dart';
import 'package:village_android/pages/health/health_submit_detail_page.dart';
import 'package:village_android/pages/health/health_submit_page.dart';

//typedef ValueCallback = void Function(Object object, bool isIncrease);

 


class HealthSubmitMutilsPage extends StatefulWidget {

  List<TabViewModel> pages = [

    TabViewModel(title: '全部', widget: HealthSubmitListPage(status: "0",items: [],)),
    TabViewModel(title: '申请中', widget: HealthSubmitListPage(status: "1",items: [])),
    TabViewModel(title: '申请成功', widget: HealthSubmitListPage(status: "2",items: [])),
    TabViewModel(title: '申请失败', widget: HealthSubmitListPage(status: "3",items: [])),
    TabViewModel(title: '申诉中', widget: HealthSubmitListPage(status: "4",items: [])),
    TabViewModel(title: '申诉成功', widget: HealthSubmitListPage(status: "5",items: [])),
    TabViewModel(title: '申诉失败', widget: HealthSubmitListPage(status: "6",items: [])),
    TabViewModel(title: '支付成功', widget: HealthSubmitListPage(status: "7",items: [])),
  ];

  HealthSubmitListPage currentPage;
  int index;

  @override
  _HealthSubmitMutilsPageState createState() => _HealthSubmitMutilsPageState();
}

class _HealthSubmitMutilsPageState extends State<HealthSubmitMutilsPage>
    with SingleTickerProviderStateMixin {
  TabController tabController;

  @override
  void initState() {
    super.initState();
    this.tabController = TabController(length: widget.pages.length,
        vsync: this);

    widget.currentPage = widget.pages[0].widget;
    widget.index = 0;
    this.tabController.addListener((){
      print(this.tabController.index);
      int index = this.tabController.index;
      widget.index = index;
      widget.currentPage = widget.pages[index].widget;
    });
  }

  @override
  void dispose() {
    super.dispose();
    this.tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Tabs(
      title: '卫生费申请管理',
      demos: widget.pages,
      tabController: this.tabController,
      voidCallback: () async {
        var page = new HealthSubmitDetailPage();
        final result = await Navigator.push(context, new MaterialPageRoute(builder: (context) => page));
        if(result!=null){
//          widget.currentPage.status = widget.index.toString();
          widget.currentPage.getData();
        }
      },

    );
  }
}
